/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-03-01 18:26:27
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-03-07 17:41:25
 * @FilePath: \utils_react_manager\app\src\store\Word\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { IWordState, ICommonAction } from '@/interface/store';
import { wordListData } from '@/api/word';

const store: IStore = {
  nameSpace: 'word',
  state:{
    wordList: [],
    count: 0
  },
  actions:{
    SET_WORD_LIST(state: IWordState, action: ICommonAction){
      return {
        ...state,
        wordList: action.payload
      }
    },
    SET_WORD_LIST_COUNT(state: IWordState, action: ICommonAction) {
      return {
        ...state,
        count: action.payload
      }
    }
  },
  mutations: {
    async getWordList(dispatch: Function, payload: IWordListPayload) {
      const { data, count } = await wordListData(payload);
      dispatch({
        type: 'SET_WORD_LIST',
        payload: data
      });
      dispatch({
        type: 'SET_WORD_LIST_COUNT',
        payload: count
      });
    }
  },
  actionNames:{
    SET_WORD_LIST: 'SET_WORD_LIST',
    SET_WORD_LIST_COUNT: 'SET_WORD_LIST_COUNT'
  }
};

let actionNames: any = {};

for(let key in store.actions){
  actionNames[key] = key
}

store.actionNames = actionNames;

export default store;